#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

bool judge(string exp) {
    stack<char> S;
    for (char ch:exp) {
        if (ch == '(' || ch == '[' || ch == '{')S.push(ch);
        else if (ch == ')') {
            if (S.empty() || S.top() != '(')return false;
            S.pop();
        }
        if (ch == ']') {
            if (S.empty() || S.top() != '[')return false;
            S.pop();
        }
        if (ch == '}') {
            if (S.empty() || S.top() != '{')return false;
            S.pop();
        }
    }
    return S.empty();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (string exp; cin >> exp;) {
        cout << (judge(exp) ? "Y" : "N") << endl;
    }

    return 0;
}
//stl stack判断括号配对问题 如果配对就会止于空栈